package com.example.demo.converter.Excel;

import com.example.demo.pojo.Product;

import java.util.ArrayList;
import java.util.List;

public class ProductConverter {

    public static List converterToProduct(List strings) {
        List<Product> products = new ArrayList<>();
        for (int i = 0; i < strings.size(); i++) {
            List<String> string = (List<String>) strings.get(i);
            Product product = new Product();
            product.setId(Integer.parseInt(string.get(0)));
            product.setName(string.get(1));
            product.setTitle(string.get(2));
            product.setPrice(Double.parseDouble(string.get(3)));
            product.setStock(Integer.parseInt(string.get(4)));
            product.setCapacity(Integer.parseInt(string.get(5)));
            products.add(product);
        }
        return products;
    }

    public static List converterToExcel(List products) {
        List<List> strings = new ArrayList<>();
        List<String> string = new ArrayList<>();
        string.add("id");
        string.add("name");
        string.add("title");
        string.add("price");
        string.add("stock");
        string.add("capacity");
        strings.add(string);
        for (int i = 0; i < products.size(); i++) {
            Product product = (Product) products.get(i);
            string = new ArrayList<>();
            string.add(product.getId().toString());
            string.add(product.getName());
            string.add(product.getTitle());
            string.add(product.getPrice().toString());
            string.add(product.getStock().toString());
            string.add(product.getCapacity().toString());
            strings.add(string);
        }
        return strings;
    }
}
